package utils

import (
	"context"
	"fmt"
)

const (
	PublishKey = "websocket"
)

func Publish(ctx context.Context, channel string, msg string) error {
	fmt.Println("消息发送成功", msg)
	err := Redis.Publish(ctx, channel, msg).Err()
	return err
}

func Subscribe(ctx context.Context, channel string) (string, error) {
	sub := Redis.Subscribe(ctx, channel)
	msg, err := sub.ReceiveMessage(ctx)
	return msg.Payload, err
}
